{include file="public/head" /}
  
  <body>
    <div class="x-body">
        <form class="layui-form" style="" method="post" action="">
            <div>
                <div class="layui-form-item"  >
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>所属组团:
                    </label>
                    <div class="layui-input-inline"  style="width: 10%">
                        <select name="group" id="group" lay-filter="group" required="" lay-verify="required">
                            <option value="">所属组团</option>
                            {if isset($groups)}
                            {foreach $groups as $group}
                            <option value="{$group}">{$group}</option>
                            {/foreach}
                            {/if}
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 10%;">
                        <select name="building" id="building" lay-filter="building" required="" lay-verify="required">
                            <option value="">所属楼栋</option>
                            {if isset($buildings)}
                            {foreach $buildings as $build}
                            <option value="{$build}">{$build}</option>
                            {/foreach}
                            {/if}
                        </select>
                    </div>
                </div>
               
                <div class="layui-form-item" >
                     <label for="username" class="layui-form-label">
                        <span class="x-red"></span>
                    </label>
                    <div class="layui-input-inline" style="width: 17%;">
                        <select name="unit" id="unit"  lay-filter="unit" required="" lay-verify="required">
                            <option value="">所属单元</option>
                            {if isset($units)}
                            {foreach $units as $uni}
                            <option value="{$uni}">{$uni}</option>
                            {/foreach}
                            {/if}
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 17%;">
                        <select name="room" id="room"  lay-filter="room" required="" lay-verify="required">
                            <option value="">所属房号</option>
                            {if isset($rooms)}
                            {foreach $rooms as $roo}
                            <option value="{$roo.room}">{$roo.room}</option>
                            {/foreach}
                            {/if}
                        </select>
                    </div>
                </div>
                
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>关系</label>
                <div class="layui-input-block">
                  
                    <input type="radio" name="relation" lay-skin="primary" title="业主" checked="" value="1">
                  
                    <input type="radio" name="relation" lay-skin="primary" title="家人" value="2">
                    <input type="radio" name="relation" lay-skin="primary" title="租客" value="3">
                      
                </div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>姓名:
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required"
                    autocomplete="off" class="layui-input" style="width: 240px;">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="x-red">*</span>手机号:
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="phone" name="phone" required="" lay-verify="required"
                    autocomplete="off" class="layui-input"  style="width: 240px;">
                </div>
            </div>
            
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    添加用户
                </button>
            </div>
      </form>
    </div>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            
            //执行一个laydate实例
            laydate.render({
            elem: '#start' //指定元素
            ,format: 'yyyyMMdd'
            });

            //执行一个laydate实例
            laydate.render({
            elem: '#end' //指定元素
            ,format: 'yyyyMMdd'
            });
        });
        
    </script>
    <script>
        layui.use(['form'], function() {
            var form = layui.form
            
            form.on('select(group)', function(f){
                
                var url = "{:url('room/getdata')}"
                $.post(url, {group: f.value, type: 1}, function(data) {
                    $('#building').html("")
                    var option = "<option value=''>所有楼栋</option>"
                    $('#building').append(option)
                    for (var i = 0; i < data.length; i++) {
                        option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                        $('#building').append(option)
                    }
                    $('#group').data('group', f.value)
                    form.render('select')
                })
            })

            form.on('select(building)', function(f){
                var data_group = $('#group').data('group')
                var get_group = "<?php if (isset($group)) { echo $group;}?>"
                var group = typeof data_group === 'undefined' ? get_group : data_group

                var url = "{:url('room/getdata')}"
                $.post(url, {building: f.value,  group: group, type:2}, function(data) {
                $('#unit').html("")
                var option = "<option value=''>所有单元</option>"
                $('#unit').append(option)
                for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                    $('#unit').append(option)
                }
                $('#building').data('building', f.value)
                form.render('select')
                })
            })

            form.on('select(unit)', function(f){
                var data_group = $('#group').data('group')
                var get_group = "<?php if (isset($group)) { echo $group;}?>"
                var group = typeof data_group === 'undefined' ? get_group : data_group

                var data_building = $('#building').data('building')
                var get_building = "<?php if (isset($building)) { echo $building;}?>"
                var building = typeof data_building === 'undefined' ? get_building : data_building
        
                var url = "{:url('room/getdata')}"
                $.post(url, {unit: f.value, group: group, building: building, type: 3}, function(data) {
                $('#room').html("")
                var option = "<option value=''>所有房间</option>"
                $('#room').append(option)
                for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                    $('#room').append(option)
                }
                $('#unit').data('unit', f.value)
                form.render('select')
                })
            })

        })
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>